package com.ok.common.utils

import android.app.Activity
import android.content.Context
import android.provider.Settings

/**
 * 屏幕控制
 */
object BrightnessUtils {

    fun getBrightness(activity: Activity): Float {
        val brightnessMode = Settings.System.getInt(
            activity.contentResolver,
            Settings.System.SCREEN_BRIGHTNESS
        )
        return brightnessMode / 255f
    }

    fun setBrightness(activity: Activity, brightness: Float) {
        val window = activity.window
        val layoutParams = window.attributes
        layoutParams.screenBrightness = brightness * 255F
        window.attributes = layoutParams
    }

}
